#coding:utf-8
from . import db 
from werkzeug.security import generate_password_hash,check_password_hash
from sqlalchemy.orm import relationship,backref


class Users(db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer,primary_key = True)
    name = db.Column(db.String(50))
    hash_psw = db.Column(db.String(255))
    password = ''
    @property
    def password(self):
        pass


    @password.setter
    def password(self,psw):
        self.hash_psw = generate_password_hash(psw)
    def verify_psw(self,psw):
        return check_password_hash(self.hash_psw,psw)
    


class Kinds(db.Model):
    __tablename__ = 't_kinds'
    id = db.Column(db.Integer,primary_key = True)
    name = db.Column(db.String(255))
    couses = relationship('Courses',backref = 'kinds',cascade = 'delete')

class Courses(db.Model):
    __tablename__ = 't_courses'
    id = db.Column(db.Integer,primary_key = True)
    title = db.Column(db.String(255))
    abstract = db.Column(db.String(255))
    addtime = db.Column(db.DateTime)
    k_id = db.Column(db.Integer,db.ForeignKey('t_kinds.id'))
    videos = relationship('Videos',backref = 'courses',cascade = 'delete')

class Videos(db.Model):
    __tablename__ = 't_videos'
    id = db.Column(db.Integer,primary_key = True)
    title = db.Column(db.String(255))
    time = db.Column(db.Integer)
    hits = db.Column(db.Integer)
    addtime = db.Column(db.DateTime)
    adstract = db.Column(db.String(255))
    t_id = db.Column(db.Integer)
    c_id = db.Column(db.Integer,db.ForeignKey('t_courses.id'))


class Teachers(db.Model):
    __tablename__ = 'teachers'
    id = db.Column(db.Integer,primary_key = True)
    name = db.Column(db.String(255))
    adstract = db.Column(db.String(255))
    level = db.Column(db.String(255))

